﻿@{
    ViewBag.Title = "UserStock";
}

@section scripts
{  
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script> 
}
   <div class="mini-splitter" style="width:100%;height:100%;">
    <div size="400" showcollapseButton="true">
        @Html.Partial("~/Views/Modular/Tool.cshtml")
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table>
                <tr>
                    <td width ="80px" align="right">用户查询: </td>
                    <td width ="110px" ><input class="mini-textbox" id ="FSearchKey" width ="110px" name = "FSearchKey"/></td>
                    <td width ="80px" align="center">
                        <a class="mini-button" iconCls="icon-search" onclick="LoadAgentList" plain="true">搜索</a>
                    </td>
                </tr>
            </table>
        </div>
        <div class="mini-fit">
                    <div id="datagrid2" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="GetPriceBookTree"
                        allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                        onrowdblclick="editClass"  sortMode="client" onselectionchanged="LoadListData">
                    <div property="columns">
                        <div type="checkcolumn" >选行</div>
                        <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                        <div field="FNumber" name="FNumber" width="80" headeralign="center" allowsort="true">编码</div>
                        <div field="FName" name="FName" width="100" headeralign="center" allowsort="true">用户名</div>
                        <div field="FClassName" name="FClassName" width="100" headeralign="center" allowsort="true">用户类型</div>
                        <div field="FRemark" name="FRemark" width="120" headeralign="center" allowsort="true">备注</div>
                    </div>
                </div>
        </div>
    </div>
       
    <div showCollapseButton="true">
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                         <span class="separator"></span>
                        <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true">新增</a>
                        <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="removeRows" plain="true">删除</a>
                         <span class="separator"></span>
                        <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                    </td>
                </tr>
            </table>       
        </div>
        <table>
            <tr>
                <td width ="100px" align="right">门店查询: </td>
                <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKeyS" name = "FSearchKeyS" onkeypress="setkeyPress()"/></td>
                <td width ="100px" align="center">
                    <a class="mini-button" iconCls="icon-search" onclick="search(0)" plain="true">查询</a>
                </td>
            </tr>
        </table>
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="../User/GetUserStocks"
                    allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client"multiSelect="true">
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">编码</div>
                    <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">门店名称</div>
                    <div field="FManage" name="FManage" width="100" headeralign="center" allowsort="true">门店管理</div>
                    <div field="FTelephone" name="FTelephone" width="100" headeralign="center" allowsort="true">联系电话</div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    mini.parse();
    var grid = mini.get("datagrid1");
    var grid2 = mini.get("datagrid2");
    function FormShown() {
        LoadAgentList();
        LoadListData(0);
    }

    function LoadListTree() {
        LoadAgentList();
    }
    function LoadAgentList() {
        var json = "[{'FSystemAppID':'"+parent.window.getSystemAppID()+"',";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
        json = json + "}]";
        grid2.load({ mjson: json });
    }


    //加载资料列表
    function LoadListData(mdatatype) {
        var sSystemAppID = parent.window.getSystemAppID();
        var node = grid2.getSelected()
        if (node) {
            var classid = node.FItemID;
            var json = "[{";
            json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
            json = json + "'mUserID':" + "'" + classid + "',";
            json = json + "'search':" + "'" + mini.getbyName("FSearchKeyS").getValue() + "',";
            json = json + "'mDatatype':" + "'" + mdatatype + "'";
            json = json + "}]";
            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;
        }
    }

    //搜索资料列表
    function search(mdatatype) {
        LoadListData(mdatatype);
    }

    function newBill() {
        var uID = parent.window.getSystemAppID();
        var node = grid2.getSelected()
        if (node.FItemID == 0) {
            mini.alert("请选择一个组再新增");
            return;
        }
        mini.open({
            url: "/GetItem/MultIndex",
            title: "用户门店权限", width: 700, height: 470,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", sTbName: "StockInfo", sSearchKey: '', ClassID:node.FItemID };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action) {
                    var json = "[";
                    for (var i = 0; i < action.length; i++) {
                        if (i > 0)
                            json = json + ',';
                        js = '{"FItemID":' + action[i].FItemID + '}';
                        json = json + js
                    }
                    json = json + "]";
                    if (json.length < 8) { return;}
                    $.post("SaveAllocStock", { json: json, ClassID: node.FItemID, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                        var ret = mini.decode(data);
                        if (ret.status == 1) {
                            mini.showTips({ content: '增加成功', state: "success", x: "center", y: "top", timeout: 3000 });
                            grid.reload();
                        }
                        else {
                            mini.alert("异常:" + ret.error);
                        }
                    });
                    grid.reload();
                }
            }
        });
    }

    //删除资料
    function removeRows() {
        var row = grid.getSelected();
        if (row) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        SetRemoveRows();
                    }
                });
        } else {
            mini.alert("请选要删除的记录");
        }
    }

    function SetRemoveRows() {
        var FSystemAppID = parent.window.getSystemAppID();
        var rows = grid.getSelecteds();
        var json = "[";
        for (var i = 0; i < rows.length; i++) {
            if (i > 0)
                json = json + ',';
            js = '{"FItemID":' + rows[i].FItemID + '}';
            json = json + js
        }
        json = json + "]";
        if (json.length < 8) {
            mini.alert("没有要保存的数据！");
            return;
        }
        $.post("RemoveAllocStockRows", { json: json, mSystemAppID: FSystemAppID }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                grid.reload();
            }
            else {
                mini.alert("异常:" + ret.error);
            }
        });
    }

</script>